package com.panshi.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.panshi.interceptor.GlobalInterceptor;
import com.panshi.tools.ResponseData;

public class DocumentController extends Controller {

    /**
     * 交易内参
     路径：/inner-trade-news
     旧路径：/application/innerTradeNewsAPI
     方法：POST, application/json
     用户权限：需要
     请求参数：

     */

    @ActionKey("/inner-trade-news")
    @Before(GlobalInterceptor.class)
    public void inner_trade_news() {

        int pageNumber=getParaToInt("pageNumber",1);
        int pageSize=getParaToInt("pageSize",10);
        String from_sql="from ot_app_deal_channel where status=? ";
        String total_sql="select count(*) "+from_sql;
        String query_sql="select id,title,description,create_time as createdAt,content,status "+ from_sql+" ORDER BY create_time desc";
        Page<Record> recordPage = Db.paginateByFullSql(pageNumber, pageSize, total_sql, query_sql, 1);

        Record result=new Record();

        result.set("firstPage",recordPage.isFirstPage());//是否第一页
        result.set("lastPage",recordPage.isLastPage());//是否最后一页

        result.set("innerTradeNewsList",recordPage.getList());//数据列表

        renderJson(ResponseData.ok().putDataValue("pageResult",result));
    }
}
